package org.example.ai_chat.controller;

import org.example.ai_chat.pojo.ai_memory;
import org.example.ai_chat.pojo.ai_session;
import org.example.ai_chat.pojo.users;
import org.example.ai_chat.service.impl.SessionServiceImpl;
import org.example.ai_chat.util.Result;
import org.example.ai_chat.util.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/session")
public class SessionController {
    @Autowired
    private SessionServiceImpl sessionService;
    @PostMapping("/set")
    public Result setSession(@RequestBody ai_session session) {
        long conversation_id=sessionService.setSession(session);
        if(conversation_id<=0){
            return Result.build(null, ResultCodeEnum.FAIL);
        }
        return Result.build(conversation_id, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/{id}")
    public Result getSession(@RequestBody users user, @PathVariable int id) {
        if(user.getUser_id()==id){
            List<List<ai_memory>> sessions = sessionService.getUserMemoryById(id);
            return Result.build(sessions, ResultCodeEnum.SUCCESS);

        }
        return Result.build(null,ResultCodeEnum.FAIL);
    }
}
